package runnables;

import net.rim.device.api.ui.UiApplication;
import screens.Controller;
import strings.WebcampusResource;
import test.GradeAnalyzer;
import beans.Course;

public class FilesAndNewsRunnable  implements Runnable, WebcampusResource{

	// RESOURCES
	//private static ResourceBundle resources = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME);

	private Course course;
	private String hash;

	// Type indicates which window to open
	private String type;

	public FilesAndNewsRunnable(Course c, String hash, String type){
		this.course=c;
		this.hash=hash;
		this.type=type;
	}

	public void run() {

		//if (course.getNews().isEmpty() || course.getFolders().isEmpty() || course.getNews()==null || course.getFolders()==null){
		GradeAnalyzer ga = GradeAnalyzer.getInstance();
		try{
			ga.getMoreInfoClase(course, hash);
		} catch (Exception e){
			System.out.println("**********************error");
		}
		//}

		//if everything is ok, open the following screen
		UiApplication.getUiApplication().invokeLater(new Runnable() {
			public void run() {
				if (type.equals("NEWS")){
					Controller.getInstance().openNewsScreen(course.getNews());
				} else if (type.equals("DOWNLOADS")){
					Controller.getInstance().openDownloadsScreen(course.getFolders());
				}
				System.out.println("********************* Opening news or downloads screen");
			}
		});
	}
}

